package com.snowj.apaas.repository.auto;

import static com.snowj.apaas.repository.auto.AgreementChangeLogDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.snowj.apaas.domain.auto.AgreementChangeLog;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface AgreementChangeLogMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.938699+08:00", comments="Source Table: agreement_change_log")
    BasicColumn[] selectList = BasicColumn.columnList(id, agreementId, oldUser, newUser, userType, createdBy, createdDate);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.935793+08:00", comments="Source Table: agreement_change_log")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.935877+08:00", comments="Source Table: agreement_change_log")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.935953+08:00", comments="Source Table: agreement_change_log")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    @Options(useGeneratedKeys=true,keyProperty="record.id")
    int insert(InsertStatementProvider<AgreementChangeLog> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.936273+08:00", comments="Source Table: agreement_change_log")
    @Insert({
        "${insertStatement}"
    })
    @Options(useGeneratedKeys=true,keyProperty="records.id")
    int insertMultiple(@Param("insertStatement") String insertStatement, @Param("records") List<AgreementChangeLog> records);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.936502+08:00", comments="Source Table: agreement_change_log")
    default int insertMultiple(MultiRowInsertStatementProvider<AgreementChangeLog> multipleInsertStatement) {
        return insertMultiple(multipleInsertStatement.getInsertStatement(), multipleInsertStatement.getRecords());
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.936606+08:00", comments="Source Table: agreement_change_log")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("AgreementChangeLogResult")
    Optional<AgreementChangeLog> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.936752+08:00", comments="Source Table: agreement_change_log")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="AgreementChangeLogResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="agreement_id", property="agreementId", jdbcType=JdbcType.BIGINT),
        @Result(column="old_user", property="oldUser", jdbcType=JdbcType.VARCHAR),
        @Result(column="new_user", property="newUser", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_type", property="userType", jdbcType=JdbcType.INTEGER),
        @Result(column="created_by", property="createdBy", jdbcType=JdbcType.VARCHAR),
        @Result(column="created_date", property="createdDate", jdbcType=JdbcType.TIMESTAMP)
    })
    List<AgreementChangeLog> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.937616+08:00", comments="Source Table: agreement_change_log")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.937735+08:00", comments="Source Table: agreement_change_log")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, agreementChangeLog, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.937825+08:00", comments="Source Table: agreement_change_log")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, agreementChangeLog, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.937904+08:00", comments="Source Table: agreement_change_log")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.938002+08:00", comments="Source Table: agreement_change_log")
    default int insert(AgreementChangeLog record) {
        return MyBatis3Utils.insert(this::insert, record, agreementChangeLog, c ->
            c.map(agreementId).toProperty("agreementId")
            .map(oldUser).toProperty("oldUser")
            .map(newUser).toProperty("newUser")
            .map(userType).toProperty("userType")
            .map(createdBy).toProperty("createdBy")
            .map(createdDate).toProperty("createdDate")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.938191+08:00", comments="Source Table: agreement_change_log")
    default int insertMultiple(Collection<AgreementChangeLog> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, agreementChangeLog, c ->
            c.map(agreementId).toProperty("agreementId")
            .map(oldUser).toProperty("oldUser")
            .map(newUser).toProperty("newUser")
            .map(userType).toProperty("userType")
            .map(createdBy).toProperty("createdBy")
            .map(createdDate).toProperty("createdDate")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.938405+08:00", comments="Source Table: agreement_change_log")
    default int insertSelective(AgreementChangeLog record) {
        return MyBatis3Utils.insert(this::insert, record, agreementChangeLog, c ->
            c.map(agreementId).toPropertyWhenPresent("agreementId", record::getAgreementId)
            .map(oldUser).toPropertyWhenPresent("oldUser", record::getOldUser)
            .map(newUser).toPropertyWhenPresent("newUser", record::getNewUser)
            .map(userType).toPropertyWhenPresent("userType", record::getUserType)
            .map(createdBy).toPropertyWhenPresent("createdBy", record::getCreatedBy)
            .map(createdDate).toPropertyWhenPresent("createdDate", record::getCreatedDate)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.938787+08:00", comments="Source Table: agreement_change_log")
    default Optional<AgreementChangeLog> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, agreementChangeLog, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.9389+08:00", comments="Source Table: agreement_change_log")
    default List<AgreementChangeLog> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, agreementChangeLog, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.938969+08:00", comments="Source Table: agreement_change_log")
    default List<AgreementChangeLog> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, agreementChangeLog, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.939026+08:00", comments="Source Table: agreement_change_log")
    default Optional<AgreementChangeLog> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.93909+08:00", comments="Source Table: agreement_change_log")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, agreementChangeLog, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.939155+08:00", comments="Source Table: agreement_change_log")
    static UpdateDSL<UpdateModel> updateAllColumns(AgreementChangeLog record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(agreementId).equalTo(record::getAgreementId)
                .set(oldUser).equalTo(record::getOldUser)
                .set(newUser).equalTo(record::getNewUser)
                .set(userType).equalTo(record::getUserType)
                .set(createdBy).equalTo(record::getCreatedBy)
                .set(createdDate).equalTo(record::getCreatedDate);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.939308+08:00", comments="Source Table: agreement_change_log")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(AgreementChangeLog record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(agreementId).equalToWhenPresent(record::getAgreementId)
                .set(oldUser).equalToWhenPresent(record::getOldUser)
                .set(newUser).equalToWhenPresent(record::getNewUser)
                .set(userType).equalToWhenPresent(record::getUserType)
                .set(createdBy).equalToWhenPresent(record::getCreatedBy)
                .set(createdDate).equalToWhenPresent(record::getCreatedDate);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.939536+08:00", comments="Source Table: agreement_change_log")
    default int updateByPrimaryKey(AgreementChangeLog record) {
        return update(c ->
            c.set(agreementId).equalTo(record::getAgreementId)
            .set(oldUser).equalTo(record::getOldUser)
            .set(newUser).equalTo(record::getNewUser)
            .set(userType).equalTo(record::getUserType)
            .set(createdBy).equalTo(record::getCreatedBy)
            .set(createdDate).equalTo(record::getCreatedDate)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2023-03-26T19:41:51.939736+08:00", comments="Source Table: agreement_change_log")
    default int updateByPrimaryKeySelective(AgreementChangeLog record) {
        return update(c ->
            c.set(agreementId).equalToWhenPresent(record::getAgreementId)
            .set(oldUser).equalToWhenPresent(record::getOldUser)
            .set(newUser).equalToWhenPresent(record::getNewUser)
            .set(userType).equalToWhenPresent(record::getUserType)
            .set(createdBy).equalToWhenPresent(record::getCreatedBy)
            .set(createdDate).equalToWhenPresent(record::getCreatedDate)
            .where(id, isEqualTo(record::getId))
        );
    }
}